#!/bin/bash

# https://developer.android.com/studio/publish/app-signing.html#signing-manually

function ecol() {
    if [[ -z "$2" ]]; then
        echo -e "\033[1;35m$1\033[0m"
    else
        echo -e "\033[$2m$1\033[0m"
    fi
}

apk_file=?
store_file=?
key_alias=?

ecol "Sign your app with your private key using jarsigner"
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 \
    -keystore $store_file \
    $apk_file $key_alias

ecol "Verify that your APK is signed"
jarsigner -verify -verbose -certs $apk_file

ecol "Align the final APK package using zipalign"
zipalign -v 4 "$apk_file" "$apk_file-aligned.apk"
